package nju.software.tagmanager.common.utils;

import com.aspose.words.*;

import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;

/**
 * @author: raychou
 * @date: 2023-12-07 10:08
 * @description:
 */
public class DocxToHtmlUtil {
    public static String getHtml(String path) throws Exception {
        ByteArrayOutputStream html = new ByteArrayOutputStream();

        LoadOptions loadOptions = new LoadOptions();
        loadOptions.getLanguagePreferences().setDefaultEditingLanguage(EditingLanguage.CHINESE_PRC);
        Document docxDocument = new Document(path, loadOptions);
        docxDocument.save(html, SaveFormat.HTML);
        HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions();
        return html.toString(StandardCharsets.UTF_8.name());
    }
}
